import fileIcons from 'file-icons-js'

export default ({ language, path }) => {
  const iconClass = fileIcons.getClassWithColor(path)
  const fileExtension = path.match(/\.?([^./\\]+)$/)[1]
  const extensionKey = fileExtension.toLowerCase()

  return language
    ? {
        name:
          extensionLanguageHash[language.toLowerCase()] ||
          language.toLowerCase(),
        extension: fileExtension,
        iconClass
      }
    : {
        name: extensionLanguageHash[extensionKey] || extensionKey,
        extension: fileExtension,
        iconClass
      }
}

const extensionLanguageHash = {
  // ALPHABETICAL ORDER
  // Names match files in: node_modules/monaco-editor/min/vs/basic-languages/src
  asp: 'vb',
  bat: 'bat',
  c: 'objective-c',
  'c++': 'cpp',
  cc: 'cpp',
  cdxml: 'powershell',
  coffee: 'coffee',
  cpp: 'cpp',
  cjs: 'coffeescript',
  cjsx: 'coffeescript',
  class: 'java',
  cs: 'csharp',
  cshtml: 'razor',
  css: 'css',
  csx: 'csharp',
  cxx: 'cpp',
  ejs: 'html',
  erb: 'html',
  es6: 'javascript',
  docker: 'dockerfile',
  dockerfile: 'dockerfile',
  'f#': 'fsharp',
  fs: 'fsharp',
  fsi: 'fsharp',
  fsx: 'fsharp',
  fsscript: 'fsharp',
  gemfile: 'ruby',
  go: 'go',
  h: 'objective-c',
  'h++': 'cpp',
  handlebars: 'handlebars',
  hh: 'cpp',
  hpp: 'cpp',
  hta: 'vb',
  htm: 'html',
  html: 'html',
  hxx: 'cpp',
  ini: 'ini',
  jade: 'pug',
  jar: 'java',
  java: 'java',
  js: 'javascript',
  json: 'json',
  jsx: 'javascript',
  less: 'less',
  ls: 'livescript',
  lua: 'lua',
  litcoffee: 'coffee',
  m: 'objective-c',
  markdown: 'markdown',
  md: 'markdown',
  mdown: 'markdown',
  mm: 'objective-c',
  msdax: 'msdax',
  mustache: 'handlebars',
  mysql: 'sql',
  tpl: 'handlebars',
  php: 'php',
  postgres: 'sql',
  postgresql: 'sql',
  postiats: 'postiats',
  ps1: 'powershell',
  ps1xml: 'powershell',
  psc1: 'powershell',
  psd1: 'powershell',
  psm1: 'powershell',
  pssc: 'powershell',
  pug: 'pug',
  py: 'python',
  pyc: 'python',
  pyd: 'python',
  pyo: 'python',
  python: 'python',
  pyw: 'python',
  pyz: 'python',
  r: 'r',
  rakefile: 'ruby',
  rb: 'ruby',
  rda: 'r',
  rdata: 'r',
  rds: 'r',
  ruby: 'ruby',
  sass: 'sass',
  sb: 'sb',
  sb2: 'sb',
  sb3: 'sb',
  scss: 'scss',
  sh: 'shell',
  sql: 'sql',
  sol: 'solidity',
  solidity: 'solidity',
  styl: 'stylus',
  stylus: 'stylus',
  swift: 'swift',
  // Add Typescript syntax support
  ts: 'typescript',
  vbhtml: 'razor',
  vb: 'vb',
  vbe: 'vb',
  vbs: 'vb',
  vue: 'html',
  wsc: 'vb',
  wsf: 'vb',
  xml: 'xml',
  yaml: 'yaml',
  yml: 'yaml'
}
